<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1" xml:lang="en"><title id="ge143896">pg_cast</title><body><p>The <codeph>pg_cast</codeph> table stores data type conversion paths, both built-in paths and
      those defined with <codeph>CREATE CAST</codeph>.</p>
    <p>Note that <codeph>pg_cast</codeph> does not represent every type conversion
      known to the system, only those that cannot be deduced from some generic
      rule. For example, casting between a domain and its base type is not
      explicitly represented in <codeph>pg_cast</codeph>. Another important
      exception is that "automatic I/O conversion casts", those performed using
      a data type's own I/O functions to convert to or from <codeph>text</codeph>
      or other string types, are not explicitly represented in
      <codeph>pg_cast</codeph>.</p>
    <p>The cast functions listed in
        <codeph>pg_cast</codeph> must always take the cast source type as their first argument type,
      and return the cast destination type as their result type. A cast function can have up to
      three arguments. The second argument, if present, must be type <codeph>integer</codeph>; it
      receives the type modifier associated with the destination type, or <codeph>-1</codeph> if
      there is none. The third argument, if present, must be type <codeph>boolean</codeph>; it
      receives <codeph>true</codeph> if the cast is an explicit cast, <codeph>false</codeph>
      otherwise. </p><p>It is legitimate to create a <codeph>pg_cast</codeph> entry in which
the source and target types are the same, if the associated function
takes more than one argument. Such entries represent 'length coercion
functions' that coerce values of the type to be legal for a particular
type modifier value.</p>
    <p>When a <codeph>pg_cast</codeph> entry has different source and target
types and a function that takes more than one argument, the entry
converts from one type to another and applies a length coercion in
a single step. When no such entry is available, coercion to a type that
uses a type modifier involves two steps, one to convert between data
types and a second to apply the modifier.</p><table id="ge143898"><title>pg_catalog.pg_cast</title><tgroup cols="4"><colspec colnum="1" colname="col1" colwidth="131pt"/><colspec colnum="2" colname="col2" colwidth="86pt"/><colspec colnum="3" colname="col3" colwidth="85pt"/><colspec colnum="4" colname="col4" colwidth="147pt"/><thead><row><entry colname="col1">column</entry><entry colname="col2">type</entry><entry colname="col3">references</entry><entry colname="col4">description</entry></row></thead><tbody><row><entry colname="col1"><codeph>castsource</codeph></entry><entry colname="col2">oid</entry><entry colname="col3">pg_type.oid</entry><entry colname="col4">OID of the source data type.</entry></row><row><entry colname="col1"><codeph>casttarget</codeph></entry><entry colname="col2">oid</entry><entry colname="col3">pg_type.oid</entry><entry colname="col4">OID of the target data type.</entry></row><row><entry colname="col1"><codeph>castfunc</codeph></entry><entry colname="col2">oid</entry><entry colname="col3">pg_proc.oid</entry><entry colname="col4">The OID of the function to use to perform this
cast. Zero is stored if the cast method does not require a function.</entry></row>
<row><entry colname="col1"><codeph>castcontext</codeph></entry><entry colname="col2">char</entry><entry colname="col3"/><entry colname="col4">Indicates what contexts the cast may be invoked
in. <codeph>e</codeph> means only as an explicit cast (using <codeph>CAST</codeph>
or <codeph>::</codeph> syntax). <codeph>a</codeph> means implicitly in
assignment to a target column, as well as explicitly. <codeph>i</codeph>
means implicitly in expressions, as well as the other cases<i>.</i></entry></row>
    <row><entry colname="col1"><codeph>castmethod</codeph></entry>
       <entry colname="col2">char</entry>
       <entry colname="col3"/>
       <entry colname="col4">Indicates how the cast is performed:<p><codeph>f</codeph> - The function identified in the <codeph>castfunc</codeph> field is used.</p>
         <p><codeph>i</codeph> - The input/output functions are used.</p>
         <p><codeph>b</codeph> - The types are binary-coercible, and no conversion is required.</p>
      </entry>
    </row>
</tbody></tgroup></table></body></topic>
